package com.learn.example.userservice.controller;

import com.learn.example.userservice.model.OrderInfo;
import com.learn.example.userservice.model.User;
import com.learn.example.userservice.service.FiegnOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @author: lfc
 * @version: 2020/5/19 9:16
 */
@RestController
@RequestMapping("/user")
public class UserController {

    private FiegnOrderService orderService;

    public FiegnOrderService getOrderService() {
        return orderService;
    }
    @Autowired
    public void setOrderService(FiegnOrderService orderService) {
        this.orderService = orderService;
    }

    @RequestMapping(value = "/info/{name}")
    @ResponseBody
    public User info(@PathVariable String name) {
        User user = new User();
        user.setName(name);
        user.setAge(10000);
        user.setUserId("userid001");
        //测试熔断
//        try {
//            Thread.currentThread().sleep(2500);
//        } catch (InterruptedException e) {
//        }

        return user;
    }

    @RequestMapping(value = "/{userid}/orderinfo")
    @ResponseBody
    public OrderInfo orderInfo(@PathVariable("userid") String userId) {

        OrderInfo orderInfo = orderService.getOrderInfoByUser(userId);

        return orderInfo;
    }
}
